package com.xff.Controller;

import com.xff.bean.HistoryPenaltyBean;
import com.xff.bean.SubscribeBean;
import com.xff.dao.BookDao;
import com.xff.dao.SubscribeDao;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

@Controller
public class PenaltyController {

    @GetMapping("/NoPaid")
    public String NoPaid(HttpServletRequest request, HttpSession session){
        if(session.getAttribute("status")!=null&&(int)session.getAttribute("status")==2) {
            ArrayList<HistoryPenaltyBean> historyPenaltyBeans=new BookDao().get_HistoryPenaltyListInfo(2);
            //将获取的结果存入请求中
            request.setAttribute("category", historyPenaltyBeans);
            return "admin_penalty";
        }
        else {
            return "redirect:/login";
        }
    }
    @GetMapping("/HasPaid")
    public String HasPaid(HttpServletRequest request, HttpSession session){
        if(session.getAttribute("status")!=null&&(int)session.getAttribute("status")==2) {
            ArrayList<HistoryPenaltyBean> historyPenaltyBeans=new BookDao().get_HistoryPenaltyListInfo(1);
            //将获取的结果存入请求中
            request.setAttribute("category", historyPenaltyBeans);
            return "admin_penalty";
        }
        else {
            return "redirect:/login";
        }
    }

    @GetMapping("/PenaltyServlet")
    public String PenaltyServlet(HttpServletRequest request, HttpSession session){
        if(session.getAttribute("status")!=null&&(int)session.getAttribute("status")==2) {

            int hid = Integer.parseInt(request.getParameter("hid"));
            int nopaid = Integer.parseInt(request.getParameter("nopaid"));
            int haspaid = Integer.parseInt(request.getParameter("haspaid"));

            new BookDao().penalty(hid,nopaid,haspaid);

            ArrayList<HistoryPenaltyBean> historyPenaltyBeans=new BookDao().get_HistoryPenaltyListInfo(2);
            //将获取的结果存入请求中
            request.setAttribute("category", historyPenaltyBeans);
            return "admin_penalty";
        }
        else {
            return "redirect:/login";
        }
    }

    @PostMapping("/SelectPenaltyServlet")
    public String SelectPenaltyServlet(HttpServletRequest request, HttpSession session){
        if(session.getAttribute("status")!=null&&(int)session.getAttribute("status")==2) {
            String name=request.getParameter("name");
            ArrayList<HistoryPenaltyBean> historyPenaltyBeans=new BookDao().get_HistoryPenaltyListInfo(name);
            //将获取的结果存入请求中
            request.setAttribute("data", historyPenaltyBeans);
            return "admin_penalty";
        }
        else {
            return "redirect:/login";
        }
    }


}
